<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">

<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<link rel="stylesheet" href="/opebs/css/bootstrap.min.css">
<link href="/bootstrap-fileinput-master/css/fileinput.css" media="all" rel="stylesheet" type="text/css"/>
<script src="/bootstrap-fileinput-master/js/fileinput.js" type="text/javascript"></script>
<script src="/bootstrap-fileinput-master/js/locales/zh.js" type="text/javascript"></script>
<div class="row-fluid">
    <form action="" method="post" class="form form-horizontal" id="form-project-add">
        <table class="table ">
            <tbody>
                <tr>
                    <td>
                        <a href="/files/template.xls" title="模板下载">
                            <img  src="/bootstrap-fileinput-master/img/excel.png" />
                        </a>
                        <a href="#" title="保存数据" style="margin-left: 50px" id="saveBtn">
                            <img alt="项目上传目标" src="/bootstrap-fileinput-master/img/save.png" />
                        </a>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                    <label class="control-label">项目入库模板导入</label>
                    <input id="inputB1" name="input-b1[]" type="file" multiple >
                    </td>
                </tr>
            </tbody>
    </table>
    </form>
</div>

<div class="easyui-layout" style="width:100%;height:100%;">
    <table id="project_import_table" class="easyui-datagrid" title="" style="width:100%;height:70%;padding-bottom: 2px;"
           data-options="rownumbers:true,
               singleSelect:true,
                  method:'get',
                  url : '',
                  fit:false,
                  toolbar:'#tb',
                  loadMsg : '数据加载中',
                  showFooter: true" >
        <thead>
        <tr>
            <th data-options="field:'proCompany',width:150,align:'center' ">公司</th>
            <th data-options="field:'proCompanyLocation',width:100,align:'center' ">地点</th>
            <th data-options="field:'proCompanyMain',width:150,align:'center' ">产品</th>
            <th data-options="field:'proCompanyNature',width:200,align:'center' ">企业性质</th>
            <th data-options="field:'proCompanyCondition',width:100,align:'center' ">企业情况</th>
            <th data-options="field:'proCompanyRequire',width:100,align:'center' ">企业需求</th>
            <th data-options="field:'proLabel',width:200,align:'center' ">工作进度</th>
            <th data-options="field:'proId',width:200,align:'center'">项目编号</th>
            <th data-options="field:'proName',width:200,align:'center'">项目名称</th>
            <th data-options="field:'proCategory',width:200,align:'center' ,formatter:proCategoryFormatter ">项目分类</th>
        </tr>
        </thead>
    </table>
</div>

<script>
    function proCategoryFormatter(value,row) {
        var result = '';
        $.ajax({
            url : '/constants/proj_category/'+value,
            async : false,
            success: function(data){
                result = data;
            }
        });
        return result;
    }
</script>

<script>
    $("#inputB1").fileinput({
        language: 'zh',
        showBrowse: true,
        uploadUrl : "/upload-json/ruku/-1",//图片上传的url，我这里对应的是后台struts配置好的的action方法
        enctype: 'multipart/form-data',
        showCaption: true,
        showPreview: false,
        previewZoomButtonClasses:'',
        preferIconicZoomPreview:false,
        theme: "explorer",
        dropZoneEnabled: false

    }).on('filepreupload', function(event, data, previewId, index){//上传中
    }).on("fileuploaded", function (event, data, previewId, index) {    //一个文件上传成功
        var form = data.form, files = data.files, extra = data.extra, response = data.response, reader = data.reader;
        var res = data.response;
        if (res.obj==='success') {
            InitImport(); //重新刷新表格数据
        }
        else if(res.obj==='error'){
            layer.msg(res.msg,{time:10*1000})
            $('#project_import_table').datagrid('loadData',{total:0,rows:[]})
        }

    }).on('fileerror', function(event, data, msg) {  //一个文件上传失败
        console.log('文件上传失败！' + msg);
    });
    function InitImport() {
        var handler = '/common/getExcelData';
        $('#project_import_table').datagrid('options').url = handler;
        $('#project_import_table').datagrid('reload');
    }

    $('#saveBtn').click(function () {
        var rows = $("#project_import_table").datagrid("getRows");
        if(rows.length===0){
            layer.msg('请先上传文件，再保存数据');
        }else{
            $.ajax({
                url : '/project-import-save',
                type : 'post',
                data : {rows:JSON.stringify(rows)},
                async : false,
                success: function(data){
                    parent.layer.alert(data)
                    parent.$('#project_table').datagrid('reload');
                },
                complete:function(XMLHttpRequest , textStatus){
                    var index=parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            });
        }
    });
</script>


<script>
    $(window).resize(function () {
       console.log('resize')
    });
</script>